package com.scs.application.modules.sys.adapter;

import com.scs.application.modules.sys.properties.SystemProperties;
import com.scs.application.modules.sys.service.SerialRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description:生成规则适配器
 */
@Component
public class SerialRuleAdapter {
    @Autowired
    private SystemProperties systemProperties;

    private List<SerialRuleService> serialRuleServices;

    @Autowired
    private void setSerialRuleServices(List<SerialRuleService> serialRuleServices) {
        this.serialRuleServices = serialRuleServices;
    }

    /**
     * 获取当前项目的SerialRule实现类
     *
     * @return
     */
    public SerialRuleService getSerialRuleService() {
        SerialRuleService serialRuleService = null;
        for (SerialRuleService ruleService : serialRuleServices) {
            if (ruleService.isSupport(systemProperties.getFlagProject())) {
                serialRuleService = ruleService;
                break;
            }
        }
        return serialRuleService;
    }

    /**
     * 根据类型获取Parameter实现类
     *
     * @param flagProject
     * @return
     */
    public SerialRuleService getSerialRuleService(Boolean flagProject) {
        SerialRuleService serialRuleService = null;
        for (SerialRuleService ruleService : serialRuleServices) {
            if (ruleService.isSupport(flagProject)) {
                serialRuleService = ruleService;
                break;
            }
        }
        return serialRuleService;
    }
}
